package com.pai4j.pgc.service.resource;
import com.pai4j.common.util.RedisUtil;
import com.pai4j.common.util.ThreadPoolExecutorUtil;
import com.pai4j.pgc.dao.community.IResourceDownloadDAO;
import com.pai4j.pgc.entity.community.ResourceDownloadEntity;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;

/**
 *  资源下载记录服务
 *
 * @author: CYM-pai
 * @date: 2025/10/27 17:37
 **/
@Slf4j
@Service
public class ResourceDownloadRecordService {

    @Autowired
    private IResourceDownloadDAO resourceDownloadDAO;
    @Autowired
    private RedisUtil redisUtil;

    /****
     * 资源购买记录
     */
    public void log(String resourceId, String userId) {
        ThreadPoolExecutorUtil.execute(() -> {
            ResourceDownloadEntity resourceDownload = new ResourceDownloadEntity();
            resourceDownload.setResourceId(resourceId);
            resourceDownload.setUserId(userId);
            resourceDownload.setDownloadDate(new Date());
            resourceDownloadDAO.save(resourceDownload);
            log.info("{} 下载了资源 {}", userId, resourceId);
        });
    }
}
